<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>GSAP Modal Animation</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      padding: 20px;
    }
    
    .modal-overlay {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.5);
      display: flex;
      justify-content: center;
      align-items: center;
      opacity: 0;
      visibility: hidden;
      z-index: 1000;
    }
    
    .modal-content {
      background: white;
      padding: 30px;
      border-radius: 8px;
      max-width: 500px;
      width: 90%;
      transform: scale(0.8);
      will-change: transform, opacity;
      box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    }
    
    .open-btn, .close-btn {
      padding: 10px 20px;
      background: #4CAF50;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      font-size: 16px;
    }
    
    .close-btn {
      background: #f44336;
      margin-top: 20px;
    }
  </style>
</head>
<body>
  <div class="modal-overlay">
    <div class="modal-content">
      <h2>欢迎使用我们的服务</h2>
      <p>这是一个使用GSAP实现的流畅弹窗动画示例。您可以点击下方按钮关闭弹窗。</p>
      <button class="close-btn">关闭弹窗</button>
    </div>
  </div>
  
  <button class="open-btn">打开弹窗</button>
  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.4/gsap.min.js"></script>
  <script>
    document.addEventListener('DOMContentLoaded', () => {
      const overlay = document.querySelector('.modal-overlay');
      const modal = document.querySelector('.modal-content');
      const openBtn = document.querySelector('.open-btn');
      const closeBtn = document.querySelector('.close-btn');
      
      // 创建时间轴
      const modalTimeline = gsap.timeline({ paused: true });
      
      // 添加动画到时间轴
      modalTimeline
        .to(overlay, {
          opacity: 1,
          visibility: 'visible',
          duration: 0.3
        })
        .fromTo(modal, 
          { 
            scale: 0.8,
            opacity: 0,
            y: 30
          },
          { 
            scale: 1,
            opacity: 1,
            y: 0,
            duration: 0.6,
            ease: 'elastic.out(1, 0.5)'
          }, '-=0.2')
        .from('.modal-content h2', {
          y: -20,
          opacity: 0,
          duration: 0.3
        }, '-=0.4')
        .from('.modal-content p', {
          y: 10,
          opacity: 0,
          duration: 0.3
        }, '-=0.3')
        .from('.close-btn', {
          y: 10,
          opacity: 0,
          duration: 0.3
        }, '-=0.2');
      
      // 打开弹窗
      openBtn.addEventListener('click', () => {
        modalTimeline.play();
      });
      
      // 关闭弹窗
      closeBtn.addEventListener('click', () => {
        modalTimeline.reverse();
      });
      
      // 点击遮罩层关闭
      overlay.addEventListener('click', (e) => {
        if (e.target === overlay) {
          modalTimeline.reverse();
        }
      });
    });
  </script>
</body>
</html>
